//
//  UIButton+Block.m
//  WBBaseProject
//
//  Created by 吴斌 on 2017/6/30.
//  Copyright © 2017年 吴斌. All rights reserved.
//

#import "UIButton+Block.h"

static char overviewKey;

@implementation UIButton (Block)

- (void)wb_handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock)block{
    objc_setAssociatedObject(self, &overviewKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [self addTarget:self action:@selector(wb_callActionBlock:) forControlEvents:event];
}

- (void)wb_callActionBlock:(id)sender{
    ActionBlock block = (ActionBlock)objc_getAssociatedObject(self, &overviewKey);
    if (block) {
        block();
    }
}

@end

